﻿using MetaSharp.Transformation.Patterns;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;

namespace MetaSharp.Transformation
{
    [DebuggerDisplay("{Display}")]
    public class RuleMetadata
    {
        public object Value { get; private set; }
        public RulePattern Origin { get; private set; }
        public IImmutableArray<MetadataAttribute> Metadata { get; private set; }
        public SourceSpan Span { get; private set; }

        public RuleMetadata(object value, RulePattern origin, SourceSpan span, IImmutableArray<MetadataAttribute> metadata)
        {
            this.Value = value;
            this.Origin = origin;
            this.Metadata = metadata;
            this.Span = span;
        }

        internal string Display
        {
            get
            {
                var atts = new string[Metadata.Length];
                for (var i = 0; i < Metadata.Length; i++)
                    atts[i] = Metadata[i].ToString();

                return string.Format(
                    CultureInfo.CurrentCulture,
                    "Metadata {{ Value={0}, Span={1}, Attributes=[{2}] }}",
                    Value,
                    Span,
                    string.Join(",", atts));
            }
        }
    }
}
